﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Web_Interface_HomePage : System.Web.UI.Page
{
    HttpCookie User;
    HttpCookie Pass;
    protected void Page_Load(object sender, EventArgs e)
    {
        User = new HttpCookie("User");
        Pass = new HttpCookie("Pass");
        ReadCookie();

    }

    public void ReadCookie()
    {
        
        string CookieUser="User";
        string CookiePass = "Pass";
        User = Request.Cookies[CookieUser];
        Pass = Request.Cookies[CookiePass];

        if(User==null || Pass == null)
        {
            Label1.Text = "Welcome Guest";
        }
        else if (User != null || Pass != null)
        {
            
           string UserValue = User.Value.ToString();
            //Response.Write(UserValue);
            Label1.Text = UserValue;
            Label2.Visible = false;
            TextBox2.Visible = false;
            TextBox1.Visible = false;
            Label3.Visible = false;
            Login.Visible = false;
                
        }
    }
    public void WriteCookie()
    {
        HttpCookie User = new HttpCookie("User");
        //Set the cookies value
        User.Value = TextBox1.Text;
        //Set the cookie to expire in 1 minute
        DateTime dtNow = DateTime.Now;
        TimeSpan tsMinute = new TimeSpan(0, 0, 1, 0);
       User.Expires = dtNow + tsMinute;


        //Add the cookie
        Response.Cookies.Add(User);

        /////////////////////
        HttpCookie Pass = new HttpCookie("Pass");

        //Set the cookies value
        Pass.Value = TextBox2.Text;

        //Set the cookie to expire in 1 minute
        Pass.Expires = dtNow + tsMinute;

        //Add the cookie
        Response.Cookies.Add(Pass);
        //reload page
        //Response.Redirect("Default.aspx");
        ////////


        //string javaScript =
        // "<script language=JavaScript>\n" +
        // "Button2_onclick();\n" +
        // "</script>";

        //RegisterStartupScript("Button2_ClickScript", javaScript);
        //ReadCookie();

        ////////////////
       // return true;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        net.aspspider.VerifyAccount va = new net.aspspider.VerifyAccount();
        if (va.execute(TextBox1.Text, TextBox2.Text))
        {
            //Response.Redirect("http://livescore.com/");
            WriteCookie();
            Response.Redirect("HomePage.aspx");
        }
        else
        {
            Response.Redirect("http://en.wikipedia.org/wiki/Parallel_port");
        }
    }
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {

    }
}
